package com.itheima.web;

import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckGroupService;
import com.itheima.support.PageResult;
import com.itheima.support.QueryPageBean;
import com.itheima.support.Result;
import com.itheima.vo.CheckGroupVO;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {
    /**
     * rpc远程服务调用
     */
    @DubboReference
    private CheckGroupService checkGroupService;

    /**
     * 修改和储存
     * @param checkGroupVO
     * @return
     */
    @PostMapping("/save")
    @PreAuthorize("hasAuthority('save_checkgroup')")
    public boolean save(@RequestBody CheckGroupVO checkGroupVO){

        return checkGroupService.saveGroup(checkGroupVO);
    }

    /**
     * 分页
     * @param queryPageBean
     * @return
     */

    //3月22日17点05分
    @PreAuthorize("hasAuthority('search_checkgroup')")
    @PostMapping("/findByPage")
    public PageResult findByPage(@RequestBody QueryPageBean queryPageBean){
        return checkGroupService.findByPage(queryPageBean);
    }


    /**
     * 逻辑删除
     * @param id
     * @return
     */
    @GetMapping("/deleteById/{id}")
    @PreAuthorize("hasAuthority('del_checkgroup')")
    public boolean deleteById(@PathVariable("id") Long id){
        return checkGroupService.removeById(id);
    }

    /**
     * 查询所有检查组
     * @return
     */
    @GetMapping("/findAll")
    public List<CheckGroup> findAll(){
        return checkGroupService.list();
    }


}
